package ${voPackage};

import com.zeng.nicecore.convert.AbstractConvertor;
import com.zeng.nicecore.util.BeanUtil;
import com.zeng.nicecore.validation.ValidGroup;
import ${entityPackage}.${entityClassName};
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
<#if packageExtend??>
    <#list packageExtend as item>
import ${item};
    </#list>
</#if>

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Null;
import java.util.Date;
import java.util.List;
<#list table.rows as row>
        <#assign
        typeName=row.type?split(" ")
        typeNamePo=(typeName?size)-1
        typeFullName=typeName[typeNamePo]
        />
<#if !typeFullName?contains("lang") && !typeFullName?contains("Date")>
import ${typeFullName};
</#if>
</#list>

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class ${className} {
<#list table.rows as row>
<#assign 
    typeName=row.type?split(".")
    typeNamePo=(typeName?size)-1
    typeFullName=typeName[typeNamePo]
            />
    //${row.desc}
    private ${typeFullName} ${row.name};
</#list>

<#if propertyExtend??>
    <#list propertyExtend as item>
    ${item}
    </#list>
</#if>

    @Null(groups = ValidGroup.add.class,message = "version must be empty when adding records ")
    private Integer version;

    @Null(groups = ValidGroup.add.class,message = "valid must be empty when adding records ")
    private Short valid;

    @Null(groups = ValidGroup.add.class,message = "code must be empty when adding records")
    @NotEmpty(groups = ValidGroup.update.class,message = "code must be excluded where update record ")
    private String code;

    @Null(groups = ValidGroup.add.class,message = "id must be empty when adding records")
    private Integer id;

    @Null(groups = ValidGroup.add.class,message = "updateDate must be empty when adding records")
    private Date updateDate;

    @Null(groups = ValidGroup.add.class,message = "insertDate must be empty when adding records")
    private Date insertDate;

    public ${entityClassName} convertTo${entityClassName}(){
        return new ${className}Convertable().voToBean(this);
    }

    public static ${className} convertTo${className}(${entityClassName} ${entityClassName?uncap_first}){
        return new ${className}Convertable().beanToVo(${entityClassName?uncap_first});
    }

    public static List<${className}> list${className}(List<${entityClassName}> ${entityClassName?uncap_first}s){
        return new ${className}Convertable().toList(${entityClassName?uncap_first}s);
    }

    public static List<${entityClassName}> list${entityClassName}(List<${className}> ${className?uncap_first}s){
        return new ${className}Convertable().toBeanList(${className?uncap_first}s);
    }

    private static class ${className}Convertable implements AbstractConvertor<${entityClassName}, ${className}> {

        @Override
        public ${className} beanToVo(${entityClassName} ${entityClassName?uncap_first}) {
            return BeanUtil.beanToVo(${entityClassName?uncap_first}, new ${className}());
        }
    
        @Override
        public ${entityClassName} voToBean(${className} ${className?uncap_first}) {
            return BeanUtil.VoToBean(${className?uncap_first}, new ${entityClassName}());
        }
    }
}